import { fromJS } from 'immutable';
import * as constants from './constants';

const defaultState = fromJS({
  dataSource: [],
  database: [],
  databaseConfig: {},
  basicInfo: {}
});

const getCon = (state, action) => {
	return state.merge({
    'databaseConfig': action.databaseConfig,
    'basicInfo': action.basicInfo,
    'database': action.database,
	});
};

export default(state=defaultState, action) => {
  switch(action.type){
    case constants.GET_DATASOURCE:
      return state.set('dataSource',action.dataSource);
    case constants.GET_ALL_DATABASE:
      return state.set('database',action.database);
    case constants.GET_CON:
      return getCon(state,action);
    default: return state;
  }
}